<?php

include_once('config.php');
include_once('model/friends.php');
include_once('model/users.php');
include_once('model/friend_requests.php');

$user_id     = Session::user()->id;
//print_r(Friends::get_all_friends($user_id));die();
$data = array (
	"logged_in" 	  => Session::is_logged_in(),
	"contents" 		  => "friends_view.php",
	"user_id"		  => $user_id,
	
	"friends" 		  => Friends::get_all_friends($user_id),
	
	//TODO: get logged in user's friend requests, format: array of objects with properties name, id
	"friend_requests" => FriendRequests::get_pending_requests($user_id)
);

$index_view = new Template('layout.php',$data);
$index_view->render();

function format_friend($friends){
	
	$user = new Users();
	
	if($friends->user1_id != Session::user()->id)
		$user->find_by_id($friends->user1_id);
	elseif($friends->user2_id != Session::user()->id)
		$user->find_by_id($friends->user2_id);
		
	return $user;
}

function format_friend_request($request){
	
	$user = new Users();
	$user->find_by_id($request->requester_id);
		
	return $user;
}

?>